var path = require("path");
var webpack = require("webpack");
var HtmlWebpackPlugin = require("html-webpack-plugin");
const baseConfig = require("./webpack.base.config");
const merge = require("webpack-merge");
module.exports = merge.merge(baseConfig, {
    entry: "./src/main.js",
    output: {
        path: path.resolve(__dirname, "./docs"),
        publicPath: "https://mtttm.github.io/vue-keyboard-cn/",
        filename: "build.js",
        filename: "build.[chunkHash:8].js",
    },
    devServer: {
        historyApiFallback: true,
        noInfo: true,
        overlay: true,
    },
    devtool: "hidden-source-map",
});

if (process.env.NODE_ENV === "production") {
    module.exports.devtool = "#source-map";
    // http://vue-loader.vuejs.org/en/workflow/production.html
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.DefinePlugin({
            "process.env": {
                NODE_ENV: '"production"',
            },
        }),
        new webpack.optimize.UglifyJsPlugin({
            sourceMap: false,
            compress: {
                warnings: false,
                drop_debugger: true,
                drop_console: true,
                pure_funcs: ["console.log"], //移除console
            },
        }),
        new webpack.LoaderOptionsPlugin({
            minimize: true,
        }),
        //生成html模版文件
        new HtmlWebpackPlugin({
            filename: "index.html",
            template: "index.html",
            favicon: "favicon.ico",
            inject: true,
        }),
    ]);
}